function initMakePlan() {
	var HOME='home';
	var ENTITY_PROFIL='profil';
	var ENTITY_LOGIN='login';
	var ENTITY_REGISTER='register';
	var ENTITY_SIZE='size';
	var ENTITY_SHOW_PLAN='showplan';
	var ENTITY_MAKE_PLAN='makeplan';
	
	getValues(ENTITY_PROFIL, null);
	getValuesWithAdditional(ENTITY_PROFIL, "cel");
	// a workaround for a flaw in the demo system (http://dev.jqueryui.com/ticket/4375), ignore!
	$( "#dialog:ui-dialog" ).dialog( "destroy" );
	
	var name = $( "#name" ),
		email = $( "#email" ),
		password = $( "#password" ),
		allFields = $( [] ).add( name ).add( email ).add( password ),
		tips = $( ".validateTips" );

	function updateTips( t ) {
		tips
			.text( t )
			.addClass( "ui-state-highlight" );
		setTimeout(function() {
			tips.removeClass( "ui-state-highlight", 1500 );
		}, 500 );
	}

	function checkLength( o, n, min, max ) {
		if ( o.val().length > max || o.val().length < min ) {
			o.addClass( "ui-state-error" );
			updateTips( "Length of " + n + " must be between " +
				min + " and " + max + "." );
			return false;
		} else {
			return true;
		}
	}

	function checkRegexp( o, regexp, n ) {
		if ( !( regexp.test( o.val() ) ) ) {
			o.addClass( "ui-state-error" );
			updateTips( n );
			return false;
		} else {
			return true;
		}
	}


	$( "#okreslenieCelu" )
		.button()
		.click(function() {
			setSelectValue("goal");
			getDataAndSet("profil","cel");
			$( "#cel-form" ).dialog( "open" );
		});
	
	$( "#cel-form" ).dialog({
		autoOpen: false,
		height: 300,
		width: 350,
		modal: true,
		buttons: {
			"Zapisz": function() {
				saveDataFromSelectWithAdditionalData("profil", "goal", "cel");	
				$( "#cel-form" ).dialog( "close" );
				$("#okreslenieCelu").addClass("isOk").append(" - uzupelnione");
			},

		},
	});
	
	$( "#okreslenieCzasu" )
		.button()
		.click(function() {
			setSelectValue("time");
			getDataAndSet("profil","czas");
			$( "#czas-form" ).dialog( "open" );
	});
	
	//Czas form
	$( "#czas-form" ).dialog({
		autoOpen: false,
		height: 300,
		width: 350,
		modal: true,
		buttons: {
			"Zapisz": function() {
				saveDataFromSelectWithAdditionalData("profil", "time", "czas");
				//saveFromDialogWithAdditionalDate("profil", "czas");	
				$("#okreslenieCzasu").addClass("isOk").append(" - uzupelnione");
				$( "#czas-form" ).dialog( "close" );
			
			},
		}
	});
	
	$( "#wybranaPartiaMiesniowa" )
		.button()
		.click(function() {
			setSelectValue("batch");
			getDataAndSet("profil","partia");
			$( "#partia-form" ).dialog( "open" );
		});
	
	//Czas form
	$( "#partia-form" ).dialog({
		autoOpen: false,
		height: 300,
		width: 350,
		modal: true,
		buttons: {
			"Zapisz": function() {
				saveDataFromSelectWithAdditionalData("profil", "batch", "partia");
				$("#wybranaPartiaMiesniowa").addClass("isOk").append(" - uzupelnione");
				$( "#partia-form" ).dialog( "close" );
			
			},
		}
	});
	
	$( "#intensywnosc" )
		.button()
		.click(function() {
			setSelectValue("intensity");
			getDataAndSet("profil","intensywnosc");
			$( "#intensywnosc-form" ).dialog( "open" );
	});
	
	//Czas form
	$( "#intensywnosc-form" ).dialog({
		autoOpen: false,
		height: 300,
		width: 350,
		modal: true,
		buttons: {
			"Zapisz": function() {
				saveDataFromSelectWithAdditionalData("profil", "intensity", "intensywnosc");
				$("#intensywnosc").addClass("isOk").append(" - uzupelnione");
				$( "#intensywnosc-form" ).dialog( "close" );
			
			},
		}
	});
	
	$( "#dostepnePrzyrzady" )
		.button()
		.click(function() {
			setCheckBoxValue("instrument");
			$( "#przyrzady-form" ).dialog( "open" );
	});
	
	
	//przyrzady form
	$( "#przyrzady-form" ).dialog({
		autoOpen: false,
		height: 300,
		width: 350,
		modal: true,
		buttons: {
			"Zapisz": function() {
				saveFromCheckbox("instrument", "profil");
				$( "#przyrzady-form" ).dialog( "close" );
				$("#dostepnePrzyrzady").addClass("isOk").append(" - uzupelnione");
			
			},
		}
	});
	
	
	$( "#wypelnienieProfilu" )
		.button()
		.click(function() {
			$( "#profil-form" ).dialog( "open" );
	});
	
	$( "#profil-form" ).dialog({
		autoOpen: false,
		height: 300,
		width: 350,
		modal: true,
		buttons: {
			"Zapisz": function() {
				saveFromDialog("profil");	
				$("#wypelnienieProfilu").addClass("isOk").append(" - uzupelnione");
				$( "#profil-form" ).dialog( "close" );
			
			},
		}
	});
	
	//function to save an entity
	var saveFromDialog = function(entity) {
		$('#'+entity+'-form').hide();
		// creating the data object to be sent to backend
		 var data=new Array();
		// collecting the field values from the form
		 var formEleList = $('form#'+entity+'-form').serializeArray();
		 for(var i=0;i<formEleList.length;i++){
			if(formEleList[i].name == "sex") {
				if(document.getElementsByName('sex')[0].checked==true){
					formEleList[i].value = "kobieta";
				} else {
					formEleList[i].value = "mezczyzna";
				}		
			} 
			data[data.length]=new param(formEleList[i].name,formEleList[i].value);
		 }
		 //setting action as PUT
		 data[data.length]=new param('action','PUT');
		 
		 console.log(data);
		 //making the ajax call
		 $.ajax({
				url : "/"+entity,
				type : "PUT",
				data:data,
				success  : function(data) {
					
				}
			});

	}
	
	//function to save an entity
	var saveFromDialogWithAdditionalDate = function(entity, underEntity) {
		$('#'+underEntity+'-form').hide();
		// creating the data object to be sent to backend
		 var data=new Array();
		// collecting the field values from the form
		 var formEleList = $('form#'+underEntity+'-form').serializeArray();
		 for(var i=0;i<formEleList.length;i++){
			if(formEleList[i].name == "sex") {
				if(document.getElementsByName('sex')[0].checked==true){
					formEleList[i].value = "kobieta";
				} else {
					formEleList[i].value = "mezczyzna";
				}		
			} 
			data[data.length]=new param(formEleList[i].name,formEleList[i].value);
		 }
		 //setting action as PUT
		 data[data.length]=new param('action','PUT');
		 
		 console.log(data);
		 //making the ajax call
		 $.ajax({
				url : "/"+entity,
				type : "PUT",
				data:data,
				success  : function(data) {
					
				}
			});

	}
	
	//zapis z selecta
	function saveDataFromSelectWithAdditionalData (entity, underEntity, itemName) {
		 var data=new Array();
		// collecting the field values from the form
		 var formEleList = $('form#'+underEntity+'-form').serializeArray();
		 
		 console.log(data);
		 var selectItem = $('#select-'+underEntity).val();
		 console.log(selectItem);
		 
	     data[data.length]=new param(itemName,selectItem);
	     
		 //setting action as PUT
		 data[data.length]=new param('action','PUT');
		 
		 
		 //making the ajax call
		 $.ajax({
				url : "/"+entity,
				type : "PUT",
				data:data,
				success  : function(data) {
					//alert(data);
				}
			});

	}
	
	//function to populate the list of an entity
	function getValues(entity, filter){
		
		if(entity == "profil"){
			var data = PROFIL_DATA;
			if(data!=null){
			var formElements = $('form#'+entity+'-form :input');
			for(var i=0;i<formElements.length;i++){
				if(formElements[i].type !="button"){
					var ele=$(formElements[i]);
					if(ele.attr('name') == "sex") {
						if(eval('data.'+ele.attr('name')) == "kobieta") {
							document.getElementsByName('sex')[0].checked=true;
						} else {
							document.getElementsByName('sex')[1].checked=true;
						}
					}
					ele.val(eval('data.'+ele.attr('name')));
					
				}
			}
			}
			return;
		}
		//specifying the success function. When the ajax response is successful then the following function will be called
		var successFn=function(resp){
			var data='';
			if(resp){
				//getting the data from the response object
				data=resp.data;
			}
			//creating the html content
			var htm='';
			if(data.length > 0){
				switch(entity) {
					case ENTITY_PROFIL :
//						/htm += data[0].name;
						var formElements = $('form#'+entity+'-form :input');
						for(var i=0;i<formElements.length;i++){
							if(formElements[i].type !="button"){
								var ele=$(formElements[i]);
								//var name = ele.attr('name');
								//alert(eval('data[0].'+ele.attr('name')));
								
								if(ele.attr('name') == "sex") {
									if(eval('data[0].'+ele.attr('name')) == "kobieta") {
										document.getElementsByName('sex')[0].checked=true;
									} else {
										document.getElementsByName('sex')[1].checked=true;
									}
								}
								ele.val(eval('data[0].'+ele.attr('name')));
								
							}
						}
						break;
					case ENTITY_SIZE :
//						/htm += data[0].name;
						var formElements = $('form#'+entity+'-create-form :input');
						for(var i=0;i<formElements.length;i++){
							if(formElements[i].type !="button"){
								var ele=$(formElements[i]);
								ele.val(eval('data[0].'+ele.attr('name')));							
							}
						}
						break;
					default:
						break;	
				}
			}
			else{
				//condition to show message when data is not available
				var thElesLength=$('#'+entity+'-list-ctr table thead th').length;
				htm+='<tr><td colspan="'+thElesLength+'">No items found</td></tr>';
			}
			$('#'+entity+'-list-tbody').html(htm);
		}
		getData("/"+entity,filter,successFn,null);
	}
	
	//function to populate the list of an entity
	function getValuesWithAdditional(entity, underEntity){
		//specifying the success function. When the ajax response is successful then the following function will be called
		
		if(entity=="profil") {
			var data = PROFIL_DATA;
			if(data!=null) {
				if(data.length > 0){
					var formElements = $('form#'+underEntity+'-form :input');
					for(var i=0;i<formElements.length;i++){
						if(formElements[i].type !="button"){
							var ele=$(formElements[i]);
							ele.val(eval('data.'+ele.attr('name')));
						}
					}
				}
			}
			return;
		}
		
		
		
		var successFn=function(resp){
			var data='';
			if(resp){
				//getting the data from the response object
				data=resp.data;
			}
			//creating the html content
			var htm='';
			if(data.length > 0){
				var formElements = $('form#'+underEntity+'-form :input');
				for(var i=0;i<formElements.length;i++){
					if(formElements[i].type !="button"){
						var ele=$(formElements[i]);
						ele.val(eval('data[0].'+ele.attr('name')));
					}
				}
			}
			else{
				//condition to show message when data is not available
				var thElesLength=$('#'+entity+'-list-ctr table thead th').length;
				htm+='<tr><td colspan="'+thElesLength+'">No items found</td></tr>';
			}
			$('#'+entity+'-list-tbody').html(htm);
		}
		getData("/"+entity,null,successFn,null);
	}
	
	function getDataAndSet(entity, underEntity) {
		if(PROFIL_DATA != null) {
			$('#select-'+underEntity).val(PROFIL_DATA[underEntity]);
		}
	}
	
	function saveFromCheckbox(entity, entityBase){
		var formname = '';
		if(entity = 'instrument') formname = 'przyrzady';
		var data=new Array();
		var formElements = $('form#'+formname+'-form :input');
		
		var newData = '';
//		console.log(formElements[0].checked);
//		console.log();
		for(var i=0;i<formElements.length;i++){
			if(formElements[i].type !="button"){
				if(formElements[i].checked) {
					newData = newData + formElements[i].value +',';
				}

			}
		}
		
		
		console.log(newData);
		
		data[data.length]=new param('action','PUT');
		data[data.length]=new param('instruments',newData);
		
			 $.ajax({
					url : "/"+entityBase,
					type : "PUT",
					data:data,
					success  : function(data) {
					//	alert(data);
					}
				});
		
	}

	
}